<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once '../comm/wjt.php';
include_once 'check.php';
include_once 'page.class.php';
include '../data/expression.php';

$shai_set=include '../data/shai.php';
$shaicat_arr=$shai_set['shai_cat'];

$keyword=$_GET["keyword"]; 
$act=$_GET['act']?$_GET['act']:'share';
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=5;
$page2=($page-1)*$pagesize;
	
if($act=='shai'){
	$sql="select a.item_title,a.seller_nick,a.num_iid,a.pay_price,a.fxje,b.image,b.id,b.catid,b.hart,b.hits,b.trade_id,b.click_url from ".$BIAOTOU."tradelist as a,".$BIAOTOU."shai as b where b.xs='shai' and a.outer_code='".$_SESSION["dduserid"]."' and a.Id=b.trade_id";
	$rs = mysql_query($sql);
	$total = mysql_num_rows($rs);	
	$sql="select a.item_title,a.seller_nick,a.num_iid,a.pay_price,a.fxje,b.image,b.id,b.catid,b.hart,b.hits,b.trade_id,b.click_url from ".$BIAOTOU."tradelist as a,".$BIAOTOU."shai as b where b.xs='shai' and a.outer_code='".$_SESSION["dduserid"]."' and a.Id=b.trade_id order by a.Id desc limit $page2,$pagesize";
	$rs = mysql_query($sql);
}
	
if($act=='share'){
	$sql="select id,title,image,price,fxje,catid,hits,hart,url,click_url,tao_id from ".$BIAOTOU."shai where dduserid='".$_SESSION["dduserid"]."' and xs='share'";
	$rs = mysql_query($sql);
	$total = mysql_num_rows($rs);	
	$sql="select id,title,keywords,image,price,fxje,catid,hits,hart,url,click_url,tao_id from ".$BIAOTOU."shai where dduserid='".$_SESSION["dduserid"]."' and xs='share' order by id desc limit $page2,$pagesize";
	$rs = mysql_query($sql);
}

if($_SESSION["dduserlevel"]<$shai_set['limit_level']){
    $buyid=0;
}
else{
    $buyid=1;
}

$tag="center";
$current='baobei';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>我的晒单分享 - 用户中心</title>

<link href="../template/<?=MOBAN?>/css/style.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/layout.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/comm.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/baobei.css" rel="stylesheet" type="text/css" />
<link href="../css/redirect.css" rel="stylesheet" type="text/css" />

<style type="text/css">
#newPreview{filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);}
#apDiv022{width: 715px;height: 88px;border-bottom-width: 1px;border-bottom-style: dashed;border-bottom-color: #CCCCCC;margin-top: 10px;float: left;}
#apDiv25{width: 70px;height: 70px;padding: 5px;float: left;border: 1px dotted #CCCCCC;margin-bottom: 5px;}
#apDiv066{width: 620px;height: 85px;float: right;}
#apDiv199{height: 40px;line-height: 40px;overflow: hidden;margin-right: 5px;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
</head>
<?php
$modtag="center";
include("../template/".MOBAN."/header_user.tpl.php");
?>
<script>
commentDefaultVal='说说你对这件宝贝的评价吧';


function OnClick(id)
{
  for(i=1;i<=10;i++)
  {
	  document.getElementById("b_"+i).className="bshop1";
  }	
  document.getElementById("b_"+id).className="bshop2";
  var typeid=document.getElementById("b_"+id).name;
  document.getElementById("shopid").value=typeid;
}

function shsend(type)
{
	if(type==1) //显示
	{
		document.getElementById("send1").style.display="block";
		document.getElementById("send2").style.display="block";
		document.getElementById("shop1").style.display="none";
		document.getElementById("shop2").style.display="none";
		document.getElementById("jt1").style.display="none";
	}
	if(type==2) //隐藏
	{
		document.getElementById("send1").style.display="none";
		document.getElementById("send2").style.display="none";
		document.getElementById("shop1").style.display="block";
		document.getElementById("shop2").style.display="block";
		document.getElementById("jt1").style.display="block";	
	}
}

function addExpression(myField, myValue)
{
    myField = document.getElementById(myField);
	if(myField.value==commentDefaultVal) myField.value='';
    //IE
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        myValue = myValue;
        sel.text = myValue;
        sel.select();
    }
    //MOZILLA
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        // save scrollTop before insert
        var restoreTop = myField.scrollTop;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length);
        if (restoreTop > 0)
        {
            // restore previous scrollTop
            myField.scrollTop = restoreTop;
        }
        myField.focus();
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    }
    else
    {
        myField.value += myValue;
        myField.focus();
    }
}

$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
msgErr=new Array();
msgErr[5]='您已经分享过这件商品';
msgErr[6]='您没有购买过商品，不能评论';
msgErr[7]='您提交的信息不全';
msgErr[8]='评论不能为空或者含有敏感词';
msgErr[9]='必须添加图片';
msgErr[15]='此商品已有人分享过，换换别的吧，O(∩_∩)O';

function closeShare(){
    $('.LightBox').hide();
	$('#jumpbox2').hide();
	$('#title').val('');
	$('#url').val('');
	$('#price').val('');
	$('#tao_img').val('');
	$('#keywords').val('');
	$('#comment').val(commentDefaultVal);
	$('#J_ImgBooth').attr('src','../images/ad.jpg');
	$('#num').text(80);
}

/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
var ret="";
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
var tt= "";

for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
var c=str2asc(chr);
tt += chr+":"+c+"n";
if(parseInt("0x"+c) > 0x7f){
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}else{
if(chr==" ")
ret+="+";
else if(strSpecial.indexOf(chr)!=-1)
ret+="%"+c.toString(16);
else
ret+=chr;
}
}
return ret;
}
function UrlDecode(str){
var ret="";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
if(chr == "+"){
ret+=" ";
}else if(chr=="%"){
var asc = str.substring(i+1,i+3);
if(parseInt("0x"+asc)>0x7f){
ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
i+=5;
}else{
ret+=asc2str(parseInt("0x"+asc));
i+=2;
}
}else{
ret+= chr;
}
}
return ret;
}

function getTaoItem(url){
    if(url==''){
		alert('网址不能为空！');
	}
	else{
		if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
		}
		else{
			$('#J_ImgBooth').attr('src','../images/wait.gif');
		    $.post("../a.php",{'fun':'get_tao_img','url':url,'xs':'share'},function(data){//alert(data);
		        var data= eval("(" + data + ")");
				$('#radio'+data.cid).attr("checked",true);
		        $('#title').val(data.title);
				$('#price').val(data.price);
				$('#url').val(url);
			    $('#J_ImgBooth').attr('src',data.img);
				$('#tao_img').val(data.img);
			    $('#dopic').hide('normal');
				clickUrl=data.clickUrl;
				nick=data.nick;
		    });
		}
	}
}

regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
$(function(){
    $('.close').click(closeShare);
	$('#noShare').click(function(){alert('您的等级不足，不能分享宝贝！');});
	$('#startShare').click(function(){
		dduserid=<?=$_SESSION['dduserid']?$_SESSION['dduserid']:0?>;
		if(dduserid>0){
			shsend(2);
		    $('.LightBox').show();
			$('#jumpbox2').show();
			$('#jiantou').css('left','118px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#dopic').show('normal');
			$('#tao_url').val('在这里粘贴宝贝的链接地址');
		}
		else{
		    alert('登陆后才可分享商品！');
			window.location='user/login.php?url='+encodeURIComponent(location.href);
		}
	    
	});
	/*$('#url').blur(function(){
		var url=$('#url').val();
		if(url!=''){
		    getTaoItem(url);
		}
	});*/
	$('#get_tao_img').click(function(){
	    var url=$('#tao_url').val();
		var f=$(this).attr('f');
		if(f=='html'){
			getTaoItem(url);
		}
		else if(f=='jpg'){
			if(url==''){
		        alert('网址不能为空！');
	        }
			else{
			    $('#J_ImgBooth').attr('src',url);
			    $('#tao_img').val(url);
			    $('#dopic').hide('normal');
			}
		} 
	});
	$('#shaiForm').submit(function(){
        var title=$('#title').val();
		var url=$('#url').val();
		var price=$('#price').val();
		var tao_img=$('#tao_img').val();
		var keywords=jQuery.trim($('#keywords').val());
		var comment=$('#comment').val();
		//temp = comment.replace(/{.*?}/gim,""); //过滤表情字符
		var catid = $('#shopid').val();
        var l=keywords.split(/\s+/).length;
		var num=parseInt($('#num').text());
		var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
		if(title==''){
		    alert('填写商品名称！');
			$('#title').focus();
		}
		else if(url==''){
		    alert('填写商品网址！');
			$('#url').focus();
		}
		else if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
			$('#url').focus();
		}
		else if(price==''){
		    alert('填写商品价格！');
			$('#price').focus();
		}
		else if(tao_img=='' || tao_img=='../images/wait.gif' || tao_img=='_310x310.jpg'){
		    alert('商品加载失败！');
			/*$('#jiantou').css('left','80px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#picFun').show();
		    $('#dopic').show('normal');*/
		}
		else if(typeof catid=='undefined'){
		    alert('选择分类');
		}
		/*else if(temp==''){
		    alert('说点什么吧，不要只发表情哦');
		}*/
		else if(num<0){
		    alert('内容超限！');
			$('#comment').focus();
		}
		else if(comment=='' || comment==commentDefaultVal){
		    alert('请添加评论内容！');
			$('#comment').focus();
		}
		else if(l>5){
		    alert('最多填写5个关键词');
			$('#keywords').focus();
		}
		else{
			$('#subShare').attr('disabled','disabled');
		    $.post("../a.php",{fun:'save_share',title:title,url:url,price:price,image:tao_img,keywords:keywords,comment:comment,catid:catid,'click_url':clickUrl,'nick':nick},function(data){//$('#title').val(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
				    alert('提交成功');
					$('#subShare').attr('disabled','');
					document.execCommand('Refresh');//closeShare();
					$('#jumpbox2').hide();
				}
				else{
				    alert(msgErr[data.msg]);
					$('#subShare').attr('disabled','');
				}
		    });
		}
		return false;
	});
	$('#comment').bind('focus keyup input paste',function(){  //采用几个事件来触发（已增加鼠标粘贴事件）   
	     $('#num').text(80-$(this).attr("value").length)  //获取评论框字符长度并添加到ID="num"元素上  
	});
	$('#openem').click(function(){
	    var left=$(this).attr('left');
		var tishi=$(this).attr('val');
		var f=$(this).attr('f');
		if(f=='jpg'){$('#tao_url').val('');}
		$('#jiantou').css('left',left);
		$('#tishi').html(tishi);
		$('#dopic').show('normal');
		$('#get_tao_img').attr('f',f);
	});
})



</script> 


<div class='layout_body'>

  <div class="uInfoTop">
     <div class="break"><a href="javascript:void();" onclick="javascript:window.history.back();"><img src="../template/<?=MOBAN?>/images/back.gif" width="29" height="30" border="0" /></a></div>
     <div class="username usernamefont"><?=$_SESSION["duoduouser"]?></div>
     <div class="userstate"><a class="ustatefont" href="exit.php">退出</a></div>
  </div>
  <div class="usertopline"></div>

  <div class="clears"></div>
  <div class="CreatL">
    <ul>
      <li><a href="tradelist.php?act=taobao">返米管理</a></li>
      <li><a href="tuiguang_url.php"> 我要推广赚米</a></li>
      <li class="UserSel"><a href="baobei.php">我的晒吧</a></li>
      <li><a href="huan.php">我的兑换</a></li>
    </ul>
  </div>

  <div class="CreatR">
    <ul class="babydetail MarginB10">
      <li <?php if($act=='share') echo "class=\"active\"";?>><a href="baobei.php?act=share">我分享的宝贝</a></li>
      <li <?php if($act=='shai') echo "class=\"active\"";?>><a href="baobei.php?act=shai">我的晒单宝贝</a></li>
      <li style="float:right;width:110px;background:#FFF"><div <?php if($buyid==1){?> id="startShare" <?php }else{?> id="noShare" <?php }?> class="fxbnt">分享我喜欢的</div></li>
    </ul>
    <div class="clears"></div>
    <div class=" clears"></div>
    
    <div align="right">
      <!--Item Start 分享-->
      <?php if($act=='share')
	  {
      while($row=mysql_fetch_array($rs)){?>
        <div class="item" style="margin-top:5px">
          <div class="picfm">
            <div class="pic"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><img src="<?=$row["image"]?>" width="70" height="70" /></a></div>
          </div>
          <div class="data" style="width:223px">
            <div class="t"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><?=$row["title"]?></a></div>
            <div class="c1" style="220px">标签：<?=$row["keywords"]?></div>
          </div>
          <div class="data" style="width:150px;margin-left:50px;display:inline">
            <div class="c2" style="width:148px">原价：<?=$row["price"]?></div>
            <?php
			if($row['fxje']>0){
				if(WEBTYPE==1){
					$gotoitem="../view.php?iid=".$row['tao_id'];
				}
				else{
					$gotoitem="../list.php?iid=".$row['tao_id'];
				}
			}
			else{
				$gotoitem="http://item.taobao.com/item.htm?id=".$row['tao_id'];
			}
			?>
            <div class="c1" style="width:148px;margin-top:30px">网址：<a target="_blank" href="<?=$gotoitem?>">点击连接</a></div>
          </div>
          <div class="data" style="width:124px">
            <div class="c2" style="width:122px">点击：<?=$row["hits"]?></div>
            <div class="c1" style="width:122px;margin-top:30px">红心：<?=$row["hart"]?></div>
          </div>
          <div class="data" style="width:124px">
            <div class="c2" style="width:122px">类别：<?=$shaicat_arr[$row["catid"]]?></div>
          </div>
        </div>
      <?php }}?>  
      <!--Item End-->
      
      <!--Item Start 兑换-->
      <?php if($act=='shai')
	  {
      while($row=mysql_fetch_array($rs)){?>
      <div class="item" style="margin-top:5px">
          <div class="picfm">
            <div class="pic"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><img src="<?=$row["image"]?>" width="70" height="70" /></a></div>
          </div>
          <div class="data" style="width:223px">
            <div class="t"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><?=$row["item_title"]?></a></div>
            <div class="c1" style="220px">原价：<?=$row["pay_price"]?></div>
          </div>
          <div class="data" style="width:150px;margin-left:30px;display:inline">
            <div class="c2" style="width:148px">原价：<?=$row["pay_price"]?></div>
            <div class="c1" style="width:148px;margin-top:30px">返米：<?=(floor($row["fxje"]*100))?>米</div>
          </div>
          <div class="data" style="width:124px">
            <div class="c2" style="width:122px">点击：<?=$row["hits"]?></div>
            <div class="c1" style="width:122px">红心：<?=$row["hart"]?></div>
          </div>
          <div class="data" style="width:140px">
            <div class="c2" style="width:138px">类别：<?=$shaicat_arr[$row["catid"]]?></div>
            <div class="c1" style="width:138px">掌柜：<a href="../shop.php?nick=<?=urlencode($row["seller_nick"])?>"><?=$row["seller_nick"]?></a></div>
          </div>
        </div>
        <?php }}?>
        <!--Item End--> 
    	<?php if($act!='add'){?>
		<div class="megas512" style="clear:both"><?php pageft($total,$pagesize,1,1,0,10,"baobei.php?act=".$act."");	echo $pagenav;?></div>
	   <?php }?>
    </div>
    <div class="clears"></div>
  </div>
  <div class="clears"></div>
</div>
<div class="lineclear" style="margin-top:50px"></div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
mysql_close();
?>

<!--分享的浮动层--> 
<div class="fxframe" id="jumpbox2">
<div class="close"></div>
  <div class="fmbox">
   <div class="SelType">
    <ul>
        <?php $i=1; foreach($shaicat_arr as $k=>$v){?>
        <li><input type="button" value="<?=$v?>"  name="<?=$k?>" id="b_<?=$i?>" onclick="OnClick(<?=$i?>);"  class="bshop1" /></li>
        <?php $i++; }?>
        <input name="shaicat" type="hidden" id="shopid" value="" />
    </ul>
   </div>
   <div class="Enter">
      <div class="jt" id="jt1"></div>
      <form>
       <div class="Editfm" id="shop1"><textarea id="tao_url" class="text" >在这里张贴宝贝的地址</textarea></div>
       <div class="bfm" id="shop2"> <input  f='html' id="get_tao_img" type="button" class="bnt" onclick="shsend(1)"  value="确 定" /></div>
     </form>
     <form id="shaiForm">
     <div class="Editfm" id="send1"><textarea id="comment" onfocus="if(this.value==commentDefaultVal){this.value=''};" class="text" ><?php if($buyid==0){?>您的等级不足，不能分享宝贝！<?php }else{?>说说你对这件宝贝的评价吧<?php }?></textarea></div>
     <div class="bfm" id="send2"> <input id="subShare" type="submit" class="bnt"  value="发 布" <?php if($buyid==0){?> disabled="disabled"<?php }?>/></div>
     <div class="line">
       <a onclick="$('#expression1').fadeIn('slow');"  id="openem" class="bp"></a><a onclick="shsend(2)" class="tb"></a>
       <div class="rtxt" style="margin-right:80px">还可以输入<b id="num" style="font-size:14px; color:#FFF">80</b>个字</div>
     </div> 
       <input type="hidden" value="" id="trade_id" />
       <input type="hidden" value="" id="tao_img" /> 
     </form>  
   </div>
   <div class="shopInfo">
      <div class="shopic"><img id="J_ImgBooth" src="<?=$navheadurl?>images/ad.jpg" width="119" height="119" /></div>
      <div class="t">名称：<input readonly="readonly" id="title" type="text" style=" width:350px; height:20px; border:0; line-height:20px;background:#333;color:#FFF" /></div>
      <div class="t">链接：<input readonly="readonly" id="url" type="text" style=" width:350px; height:20px; border:0; line-height:20px;background:#333;color:#FFF" /></div>
      <div class="t">价格：<input readonly="readonly" type="text" style=" width:60px; height:20px;line-height:20px;border:0;background:#333;color:#FFF;font-size:12px" id="price" />元</div>
      <div class="t">标签：<input id="keywords" type="text" style=" width:316px; height:29px; border:1px solid #d2caca; line-height:29px;color:#c7c3c3" value="填写商品关键字，用空格隔开"  /></div>
   </div>
  </div>
  
  <!--表情层-->
  <div class="emfm" id="expression1">
   <div class="top"><img src="../template/<?=MOBAN?>//images/bqjt.gif" height="12" width="11" border="0" style="margin-left:45px" /></div>
   <div class="SelEm">
    <div class="emlist">
       <ul>
		<?php foreach($expression as $k=>$v){?>
        <li><img src="<?=$navheadurl?>images/emoticons/<?=$k?>.gif" style="cursor:pointer" onclick="addExpression('comment','{<?=$v?>}');"/></li>
		<?php }?>
      </ul>
    </div>
    <a onclick="$('#expression1').fadeOut('slow');"><div class="emclose"></div></a>
   </div>
  </div>
</div>
<script type="text/javascript">
OnClick(1);
shsend(2);
</script>

</body>
</html>
